


#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import "Reachability.h"
#import <netinet/in.h>
/*
typedef enum {
	NotReachable = 0,
	ReachableViaWiFi,
	ReachableViaWWAN
} NetworkStatus;*/
#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"

@protocol ReachabilityDelegate;

@interface CustomReachability: NSObject
{
	BOOL localWiFiRef;
	SCNetworkReachabilityRef reachabilityRef;
	
	CustomReachability* internetReachable;
    CustomReachability* hostReachable;
	NSObject <ReachabilityDelegate> *delegate;
    
    BOOL isInBGThread;
	
}

@property (nonatomic, retain) CustomReachability* internetReachable;
@property (nonatomic, retain) CustomReachability* hostReachable;
@property (nonatomic, assign) NSObject <ReachabilityDelegate> *delegate;
@property BOOL isInBGThread;
- (void) checkNetworkStatus:(NSNotification *)notice;
- (void) startCheckInternetConnectionAndNotifyDelegate;
- (void) checkInternetConnection;
- (void) checkHost:(NSString*)hostName;
- (void) checkHostName:(NSNotification *)notice;

//newReachabilityWithHostName- Use to check the reachability of a particular host name. 
+ (CustomReachability*) newReachabilityWithHostName: (NSString*) hostName;

//newReachabilityWithAddress- Use to check the reachability of a particular IP address. 
+ (CustomReachability*) newReachabilityWithAddress: (const struct sockaddr_in*) hostAddress;

//reachabilityForInternetConnection- checks whether the default route is available.  
//  Should be used by applications that do not connect to a particular host
+ (CustomReachability*) newReachabilityForInternetConnection;

//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (CustomReachability*) newReachabilityForLocalWiFi;

//Start listening for reachability notifications on the current run loop
- (BOOL) startNotifier;
- (void) stopNotifier;

- (NetworkStatus) currentReachabilityStatus;
//WWAN may be available, but not active until a connection has been established.
//WiFi may require a connection for VPN on Demand.
- (BOOL) connectionRequired;

@property int reachType;

@end

@protocol ReachabilityDelegate
@optional
- (void) connectionOnViaWIFI:(CustomReachability*)reachability;
- (void) connectionONViaWWAN:(CustomReachability*)reachability;
- (void) hostReachable:(CustomReachability*)reachability;
- (void) hostNotReachable:(CustomReachability*)reachability;
- (void) hostReachableViaWIFI:(CustomReachability*)reachability;
- (void) hostReachableViaWWAN:(CustomReachability*)reachability;

@required
- (void) connectionOff:(CustomReachability*)reachability;
- (void) connectionOn:(CustomReachability*)reachability;

@end



